package com.android.accessibility.service;

import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

import com.android.accessibility.R;
import com.android.accessibility.activity.HomeActivity;
import com.android.accessibility.function.QQOnekeyforwardingVideo;

public class QQObserverService extends Service {

    private int NOTI_SERV_RUNNING = R.string.qq_service_running;
    private QQOnekeyforwardingVideo mQQOnekeyforwardingVideo = null;

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        if (mQQOnekeyforwardingVideo == null) {
            mQQOnekeyforwardingVideo = new QQOnekeyforwardingVideo(this);
        }
        mQQOnekeyforwardingVideo.stopOnekeyForward();
        mQQOnekeyforwardingVideo.startOnekeyForward();
        showNotification(NOTI_SERV_RUNNING, R.drawable.start);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mQQOnekeyforwardingVideo != null) {
            mQQOnekeyforwardingVideo.stopOnekeyForward();
            mQQOnekeyforwardingVideo = null;
        }
        stopForeground(true);
    }

    private void showNotification(int resId, int iconId) {
        CharSequence text = getText(resId);
        Notification notification = new Notification(iconId, text,
                System.currentTimeMillis());
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, HomeActivity.class), 0);
        notification.setLatestEventInfo(this, getText(R.string.onekey_label),
                text, contentIntent);
        notification.flags = Notification.FLAG_ONGOING_EVENT;
        startForeground(resId, notification);
    }
}
